package com.jackstraw.jack_base.remote_command.entity;

import com.jackstraw.jack_base.util.StringUtil;
import com.jackstraw.jack_base.util.entity.enums.DataBaseEnum;
import com.jackstraw.jack_base.util.exception.BadRequestException;
import lombok.Data;
import org.apache.commons.lang3.ObjectUtils;

import static com.jackstraw.jack_base.remote_command.entity.EnvProperties.DEFAULT_DATASOURCE;

@Data
public class DataSourceProperties {

    private DataBaseEnum dataBaseEnum;
    private String ip;
    private String port;
    private String username;
    private String password;
    private String dbName;

    public DataBaseEnum getDataBaseEnum() {
        return ObjectUtils.isEmpty(this.dataBaseEnum) ? DEFAULT_DATASOURCE : this.dataBaseEnum;
    }

    public String getIp() {
        if (StringUtil.StringUtilsBylang3.isEmpty(this.ip)) {
            throw new BadRequestException("3100000001", "数据库连接属性不能为空");
        }
        return this.ip;
    }

    public String getPort() {
        if (StringUtil.StringUtilsBylang3.isEmpty(this.port)) {
            throw new BadRequestException("3100000001", "数据库连接属性不能为空");
        }
        return this.port;
    }

    public String getUsername() {
        if (StringUtil.StringUtilsBylang3.isEmpty(this.username)) {
            throw new BadRequestException("3100000001", "数据库连接属性不能为空");
        }
        return this.username;
    }

    public String getPassword() {
        if (StringUtil.StringUtilsBylang3.isEmpty(this.password)) {
            throw new BadRequestException("3100000001", "数据库连接属性不能为空");
        }
        return this.password;
    }

}
